package com.javasm.sys.controller;

import com.javasm.commons.base.BaseController;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.commons.entity.TableDatas;
import com.javasm.commons.enums.E;
import com.javasm.process.entity.ProcessDef;
import com.javasm.process.service.ProcessDefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("processdef")
public class ProcessDefController extends BaseController {
    @Autowired
    private ProcessDefService processDefService;

    @GetMapping("getprocess")
    public AxiosResult getprocess(ProcessDef processDefine){
        startPage();
        List<ProcessDef> list = processDefService.listProcessDefAndDeptAndPos(processDefine);
        TableDatas tableDatas = new TableDatas(list);
        return AxiosResult.suc(tableDatas);
    }

    @GetMapping("getOneById")
    public AxiosResult getOneById(String id){
        ProcessDef processDefine = processDefService.getById(id);
        return AxiosResult.suc(processDefine);
    }


    @PostMapping
    public  AxiosResult insert(@RequestBody ProcessDef processDefine){
        boolean flag = processDefService.save( processDefine);
        return isok(flag);
    }

    @PutMapping
    public  AxiosResult updateByid(@RequestBody ProcessDef processDefine){
        boolean flag = processDefService.updateById(processDefine);
        return isok(flag);
    }

    @DeleteMapping
    public  AxiosResult delById(String ids) {
        String[] myid = ids.split(",");
        boolean flag = processDefService.removeByIds(Arrays.asList(myid));
        return isok(flag);
    }
}
